<?php
    require('00_init.php');
    //获取页码pno，默认为1
    @$pno=$_REQUEST['pno'];
    @$low=$_REQUEST['low'];
    @$high=$_REQUEST['high'];
    @$kw=$_REQUEST['kw'];
     if(!$low)$low=0;
     if(!$high)$high=100000000;
    if(!$pno)$pno=1;//默认显示第一页
    else $pno=intval($pno);
    //获取每页条数默认8
    @$pageSize=$_REQUEST['pageSize'];
    if(!$pageSize) $pageSize=8;//默认每页显示8条记录
    else $pageSize=intval($pageSize);
    //计算初始位置
    $start=($pno-1)*$pageSize;
    $sql="SELECT p.category,p.lid,p.title,p.price,p.spec,p.expire,f.name,pic.sm";
    $sql.= " FROM xz_laptop p,xz_laptop_family f,xz_laptop_pic pic";
    $sql.= " WHERE p.family_id=f.fid and p.lid=pic.laptop_id and p.title like '%$kw%' and price>=$low and price<=$high";
    $sql.=" GROUP BY p.lid";
    $sql.=" LIMIT $start,$pageSize ";
     $request=mysqli_query($conn,$sql);
     if(!$request){
        echo "查询失败，请检查SQL语句：".$sql;
     }else{
       $rows= mysqli_fetch_all($request,MYSQLI_ASSOC);
       //获取查询数据
       //获取总页数
        $sql="select count(*) from xz_laptop where title like '%$kw%' and price>=$low and price<=$high";

        $request=mysqli_query($conn,$sql);
        $row=mysqli_fetch_row($request);
        $count=intval($row[0]);
        $pageCount=ceil($count/$pageSize);
        //获取当前页数
        $nowPage=$pno;
        //获取每页显示条数
        $pageSize=$pageSize;
        $outPut=[
            "recordCount"=>$count,//总记录数
            "pageCount"=>$pageCount,//总页数
            "nowPage"=>$nowPage,//当前页数
            "pageSize"=>$pageSize,//页大小
            "rows"=>$rows,//当前页内容
            "kw"=>$kw,
            "low"=>$low,
            "high"=>$high
        ];
           if(count($rows)){
               echo json_encode($outPut);
            //echo '{"recordCount":'.$count.',"pageCount":'.$pageCount.',"nowPage":'.$nowPage.',"pageSize":'.$pageSize.',"data":'.$data.'}';//总记录数,总页数，当前页数，页大小，当前页内容
           }else{
             echo '{"code":0,"msg":"暂无数据"}';
           }
     }